<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Ref_harga extends CI_Controller {
	private $limit=10;

	function __construct(){
		parent::__construct();
		
		$index	= $this->config->item('index_page');
		$host	= $this->config->item('base_url');

		$this->url = empty($index) ? $host : $host . $index . '/';
		$this->user	= unserialize(base64_decode($this->session->userdata('user')));	
		$this->load->model('mHarga');
		
		//get session.. 'user' tuh nama session yang udah di set 
//		$this->user	= unserialize(base64_decode($this->session->userdata('user')));		
	}
	function index($offset=0,$order_column='ID_BARANG', $order_type='asc')
	{
	if (!empty($this->user)){
		if(empty($offset)) $offset=0;
		if(empty($order_column)) $order_column='ID_BARANG';
		if(empty($order_type)) $order_type='asc';
		//todo : check for valid_barang column
		
		//load data siswa
		$ref_harga=$this->mHarga->get_paged_list($this->limit,$offset,$order_column,$order_type)->result();
		
		//generate pagination
		$config['base_url']=site_url('admin/ref_harga/index/');
		$config['total_rows']=$this->mHarga->count_all();
		$config['per_page']=$this->limit;
		$config['uri_segment']=3;
		$this->pagination->initialize($config);
		$data['pagination']=$this->pagination->create_links();
		
		//generate table data
		$this->table->set_empty("&nbsp;");
		$new_order=($order_type=='asc'?'desc':'asc');
		$this->table->set_heading(
			'id barang', 'tanggal pemberlakuan','harga produksi','persen laba','Actions');
			$i=0+$offset;
			foreach($ref_harga as $harga){
				$this->table->add_row($harga->ID_BARANG,$harga->TGL_PEMBERLAKUAN,$harga->HARGA_PROD,$harga->PERSEN_LABA,anchor('siswa/update/'.$harga->ID_BARANG,'update',array('class'=>'update')).' '.anchor('siswa/delete/'.$harga->ID_BARANG,'delete',array('class'=>'delete','onclick'=>"return confirm('Apakah Anda yakin ingin menghapus data siswa?')"))
				);
			}
			$data['table']=$this->table->generate();
			
			if($this->uri->segment(3)=='delete success') $data['message']='Data berhasil dihapus';
			else if ($this->uri->segment(3)=='add_success') $data['message']='Data berhasil ditambah';
			else $data['message']='';
			//load view
			$data['url'] = $this->url;
			$data['header'] = $this->load->view('admin/header/header', $data, true);
			$data['menu'] = $this->load->view('admin/menu/menu', $data, true);
			$data['content'] = $this->load->view('admin/rcontent/ref_harga/ref_harga', $data, true);
			$this->load->view('index', $data);
		}
	   else
	   {
		 //If no session, redirect to login page
		 redirect('admin/login');
	   }
	}
	
	function get_user(){
		$post = $this->input->post();
		/**
			Process
		**/
		
		$this->index();
	}
	
	function test_get(){
		$get = $this->input->get();
		/**
			Process
		**/
		
	}
	
}